package com.ruoyi.common.utils;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class BigFile {
    public static void main(String[] args){
        String[] keywords = {
                "INSERT INTO `za_monitor_warning` VALUES",
                "INSERT INTO `za_monitor_water` VALUES",
                "INSERT INTO `za_monitor_electric` VALUES",
                "INSERT INTO `za_monitor_warning_history` VALUES",
                "INSERT INTO `za_monitor_water_history` VALUES",
                "INSERT INTO `za_monitor_electric_history` VALUES",
                "INSERT INTO `sys_logininfor` VALUES",
                "INSERT INTO `sys_oper_log` VALUES",
        };
        String inFile = "D:\\360极速浏览器X下载\\db-31-12-2023.sql";
        String outFile = "D:\\360极速浏览器X下载\\db-31-12-2023_reduce.sql";
        reduce(inFile, outFile, keywords);
    }

    public static void reduce(String inFile, String outFile, String[] keywords){
        FileInputStream fis;
        FileOutputStream fos;
        try{
            fis = new FileInputStream(inFile);
            fos = new FileOutputStream(outFile);
            BufferedReader br = new BufferedReader(new InputStreamReader(fis));
            while (true){
                String line = br.readLine();
                if(line == null){
                    break;
                }
                boolean m = false;
                for(String key:keywords) {
                    if (line.startsWith(key)) {
                        m = true;
                    }
                }
                if(!m){
                    fos.write(line.getBytes(StandardCharsets.UTF_8));
                    fos.write("\r\n".getBytes(StandardCharsets.UTF_8));
                }
            }
            fis.close();
            fos.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
